package com.eber.demo.design.builder;

import lombok.Data;

// 产品类
class Car {
    private final String engine;
    private final String wheel;
    private final String body;

    public Car(CarBuilder builder) {
        this.engine = builder.getEngine();
        this.wheel = builder.getWheel();
        this.body = builder.getBody();
    }

    @Override
    public String toString() {
        return "Car{" +
                "engine='" + engine + '\'' +
                ", wheel='" + wheel + '\'' +
                ", body='" + body + '\'' +
                '}';
    }
}

// 建造者类
@Data
class CarBuilder {
    private String engine;
    private String wheel;
    private String body;

    public CarBuilder engine(String engine) {
        this.engine = engine;
        return this;
    }

    public CarBuilder wheel(String wheel) {
        this.wheel = wheel;
        return this;
    }

    public CarBuilder body(String body) {
        this.body = body;
        return this;
    }

    public Car build() {
        return new Car(this);
    }
}

public class BuilderApplication {
    public static void main(String[] args) {
        Car car = new CarBuilder()
                .engine("V8")
                .wheel("Steel Wheel")
                .body("Leather Body")
                .build();

        System.out.println(car);
    }
}
